const url = 'http://m.wufazhuce.com/one'
const puppeteer = require('puppeteer')

const sleep = time => new Promise(res => {
    setTimeout(res, time)
})

;(async () => {
    console.log('kais')

    const browser = await puppeteer.launch({
        args: ['--no-sandbox'],
        dumpio: false
    })
    const page = await browser.newPage()
    await page.goto(url, {
        waitUntil: 'networkidle2'
    })

    await sleep(300)

    // await page.waitForSelector('.more')

    // for(let i=0;i<5;i++){
    //     await sleep(3000)
    //     await page.click('.more')
    // }
    const result = await page.evaluate(() => {
        var $ = window.$
        var items = $('.ui-content .item-list .item-text')
        var links = []

        if(items.length>=1){
            items.each((index, item) => {
                console.log(item)
                let it = $(item)
                let time = it.find('.item-picture-date').text()
                let VOL = it.find('.issue-no').text()
                let aUrl = it.find('.div-link').attr('href')
                let img = it.find('img').attr('src')
                let author = it.find('.picture-author').eq(0).text() + '&' + it.find('.picture-author').eq(1).text()
                let text = it.find('.picture-content').text()
                links.push({
                    time,
                    VOL,
                    aUrl,
                    img,
                    author,
                    text
                })
            })
        }
        return links
    })
    browser.close()
    // console.log(result)
    process.send({result})
    process.exit(0)
})()